package innerclassdemo;

class OuterClass2{
    public int data1 = 10;
    private int data2 = 20;
    public static int data3 = 30;

    public void method(){
        System.out.println("OuterClass::method()");
    }

    /**
     * 静态内部类当中的一些问题
     * 1.如何实例化静态内部类
     *      OuterClass2.InnerClass innerClass = new OuterClass2.InnerClass();
     * 2.在静态内部类当中 只能访问外部类的静态的成员
     *      那么如果要访问外部类的非静态成员  那么怎么访问？ 提供外部类对象
     */


    static class InnerClass{
        public int data4 = 40;
        private int data5 = 50;
        public static int data6 = 60;

        OuterClass2 out = new OuterClass2();//null

        InnerClass(){
            System.out.println("InnerClass()");
        }

        InnerClass(OuterClass2 out){
            this.out = out;
            System.out.println("InnerClass()");
        }

        public void method(){
            //System.out.println(OuterClass2.this.data1);
            System.out.println(out.data1);
            System.out.println(out.data2);
            System.out.println(data3);
            System.out.println(data4);
            System.out.println(data5);
            System.out.println(data6);
            System.out.println("innerclass的method的方法");
        }
    }

}

class Test{
    public int a = 19;
    public void test(){
        System.out.println("test()!");
    }
}

public class TestDemo2 {
    public static void main(String[] args) {
        //重写内部类的方法
        new Test(){
            public int c = 10;
            public void test1(){
                System.out.println("hahah!");
            }

            @Override
            public void test() {
                System.out.println("woqu");
                System.out.println(a);
            }
        }.test();
    }

    public static void main1(String[] args) {
        OuterClass2.InnerClass innerClass = new OuterClass2.InnerClass(new OuterClass2());
        innerClass.method();
    }
}
